package org.example.day;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/06/20 21:02
 */
public class Solution11 {

    public static void main(String[] args) {
        Solution11 solution = new Solution11();
        System.out.println(solution.maxArea(new int[]{1,8,6,2,5,4,8,3,7}));
    }

    public int maxArea(int[] height) {
        int left = 0;
        int right = height.length-1;

        int max = 0;

        while(left < right){
            max = Math.max(calArea(height, left, right), max);
            //短的边，会导致面积变小
            if(height[right] >= height[left]){
                left++;
            }else {
                right--;
            }
        }

        return max;
    }

    private int calArea(int[] height, int left, int right) {
        return (right-left) * Math.min(height[left], height[right]);
    }

}
